home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-01.zip / 01 / Hity z okladki / OrgPlus 6 SBE / ORGPL.CAB / listCtrl.js < prev    next >
Text File  |  2006-09-20  |  8KB  |  326 lines

  1.  
  2. var g_currentID = 1;
  3.  
  4. var LCF_SHOWCAPTURE = 1;
  5. var LCF_HIGHLIGHT   = 2;
  6. var LCF_SHOWGRID    = 4;
  7. var LCF_DEFAULT     = LCF_HIGHLIGHT;
  8.  
  9. function ListCtrl( p_oParentElement )
  10. {
  11.   this.Create       = _ListCtrl_Create;
  12.   this.Add          = _ListCtrl_Add;
  13.   this.Remove       = _ListCtrl_Remove;
  14.   this.GetStyle     = _ListCtrl_GetStyle;
  15.   this.RemoveAll    = _ListCtrl_RemoveAll;
  16.   this.AddColumn    = _ListCtrl_AddColumn;
  17.   this.RemoveColumn = _ListCtrl_RemoveColumn;
  18.   this.ClearTable   = _ListCtrl_ClearTable;
  19.   this.Show         = _ListCtrl_Show;
  20.   this.SetWidth     = _ListCtrl_SetWidth;
  21.   this.ShowGrid     = _ListCtrl_ShowGrid;
  22.   
  23.   this.Columns      = new Array();
  24.   this.ID           = g_currentID++;
  25.   this.Style        = LCF_DEFAULT;
  26.   this.table        = null;
  27.   this.RowsCount    = 0;
  28.   this.ColumnsCount = 0;
  29.   
  30.   this._parent      = null;
  31.   
  32.   this.HighlightColor = "#eeeeee";
  33.   
  34.   if( typeof(p_oParentElement) == 'undefined' )
  35.     this.Create( p_oParentElement );
  36. };
  37.  
  38. function ListCtlColumn( p_sColumnCapture, p_iWidth )
  39. {
  40.   if( typeof(p_iWidth) == 'undefined' || p_iWidth == null )
  41.     p_iWidth = 100;
  42.     
  43.   this.SetWidth = function( p_iWidth){ this.Width = p_iWidth; };
  44.     
  45.   this.Capture  = p_sColumnCapture;
  46.   this.ID       = g_currentID++;
  47.   this.Width    = p_iWidth;
  48.   
  49.   this.Cells  = new Array();
  50.   this.CellsCount = 0;
  51. };
  52.  
  53. function ListCtlCell( p_sValue, p_iColumnsCount )
  54. {
  55.   if( typeof(p_iColumnsCount) == 'undefined' || p_iColumnsCount == 0 || p_iColumnsCount < 1 )
  56.     p_iColumnsCount = 1;
  57.   
  58.   this.Value = p_sValue;
  59.   this.ColumnsCount = p_iColumnsCount;
  60. }
  61.  
  62. function _ListCtrl_Create( p_oParentElement )
  63. {
  64.   if( typeof( p_oParentElement ) == 'undefined' )
  65.     return;
  66.  
  67.   this.table = document.createElement("<table width='100%'></table>");
  68.   p_oParentElement.appendChild( this.table );
  69. //  this.table.width = "100%";
  70.   this.table.style.zIndex = 0;
  71.   this.table.cellSpacing = 0;
  72.   this.table.cellpadding = 0;
  73.   this.table.style.backgroundColor = "transparent";
  74.   
  75.   this._parent = p_oParentElement;
  76.   
  77.   if( this.ColumnsCount > 0 && this.RowsCount > 0 )
  78.     this.Show();
  79. }
  80.  
  81. function _ListCtrl_Add( p_oObj )
  82. {
  83.   if( typeof( p_oObj ) == 'undefined' || p_oObj == null )
  84.     return;
  85.   
  86.   for( i = 0; i < this.Columns.length; ++i )
  87.   {
  88.     var pVal = " ";
  89.     var iColumnsCount = 1;
  90.     if( typeof(p_oObj[i]) != 'undefined' )
  91.     {
  92.       pVal = p_oObj[i];
  93.       iColumnsCount = p_oObj[i].ColumnsCount;
  94.     }
  95.     
  96.     this.Columns[i].Cells[ this.Columns[i].CellsCount ] = pVal;
  97.     this.Columns[i].CellsCount++;
  98.     
  99.     for( var t=i+1; (t < this.Columns.length)&&((t-i) < iColumnsCount); ++t )
  100.     {
  101.       var o =  new ListCtlCell( "", 1);
  102.       o.Empty = true;
  103.       this.Columns[t].Cells[ this.Columns[t].CellsCount ] = o;
  104.       this.Columns[t].CellsCount++;
  105.     }
  106.     i = t - 1;
  107.   };
  108.   
  109.   ++this.RowsCount;
  110. }
  111.  
  112. function _ListCtrl_Remove()
  113. {
  114.   throw "not implement";
  115. }
  116.  
  117. function _ListCtrl_ShowGrid( p_bFlag )
  118. {
  119.   if( typeof(p_bFlag) == 'undefined' )
  120.     p_bFlag = true;
  121.     
  122.   if( p_bFlag == true )
  123.   {
  124.     this.Style |= LCF_SHOWGRID;
  125.   }
  126.   else if( p_bFlag == false )
  127.   {
  128.     this.Style &= ~LCF_SHOWGRID;
  129.   }
  130. }
  131.  
  132. function _ListCtrl_GetStyle()
  133. {
  134.   return this.Style;
  135. }
  136.  
  137. function _ListCtrl_RemoveAll()
  138. {
  139.   for( i = 0; i < this.Columns.length ; ++i)
  140.   {
  141.     var oColumn = this.Columns[ i ];
  142.     for( ; oColumn.CellsCount > 0; )
  143.     {
  144.       oColumn.Cells[ oColumn.CellsCount ] = null;
  145.       oColumn.CellsCount--;
  146.     }
  147.   };
  148.   
  149.   this.RowsCount    = 0;
  150. }
  151.  
  152. function _ListCtrl_AddColumn( p_sColumnCapture, p_iColumnWidth )
  153. {
  154.   var oNewColumn = new ListCtlColumn( p_sColumnCapture, p_iColumnWidth );
  155.   this.Columns[ this.ColumnsCount ] = oNewColumn;
  156.   this.ColumnsCount++;
  157.   
  158.   for( i = 0; i < this.RowsCount; ++i )
  159.   {
  160.     oNewColumn.Cells[oNewColumn.CellsCount] =  new ListCtlCell("", 1);
  161.     oNewColumn.CellsCount++;
  162.   }
  163. }
  164.  
  165. function _ListCtrl_RemoveColumn()
  166. {
  167.   throw "not implement";
  168. }
  169.  
  170. function GetCellAbsolutePosition( p_oCell )
  171. {
  172.   var iOffsetLeft = p_oCell.offsetLeft;
  173.   var iOffsetTop  = p_oCell.offsetTop;
  174.  
  175.   var oParentElement = p_oCell.parentElement;
  176.   while( oParentElement != null )  
  177.   {
  178.     if( oParentElement.tagName == "CENTER" || oParentElement.tagName == "TD" ) 
  179.     {
  180.       iOffsetLeft += oParentElement.offsetLeft;
  181.       oParentElement = oParentElement.parentElement;
  182.       continue;
  183.     }
  184.       
  185.     iOffsetLeft += oParentElement.offsetLeft;
  186.     iOffsetTop  += oParentElement.offsetTop;
  187.     
  188.     oParentElement = oParentElement.parentElement;
  189.   }
  190.   
  191.   var obj = new Object();
  192.   obj.x = iOffsetLeft;
  193.   obj.y = iOffsetTop;
  194.   
  195.   return obj;
  196. }
  197.  
  198. function _ListCtrl_Show()
  199. {
  200.   if( typeof(this.table) == 'undefined' || this.table == null )
  201.     return;
  202.  
  203.   this.ClearTable();
  204.   
  205.   for( iIndex = 0; iIndex < this.RowsCount; ++iIndex )
  206.     this.table.insertRow( iIndex );
  207.    
  208.   var iOffset = 0; 
  209.   if( this.GetStyle() & LCF_SHOWCAPTURE )
  210.   {
  211.     var oCaptureRow = this.table.insertRow(0);
  212.     for( var i = 0; i < this.ColumnsCount; ++i )
  213.     {
  214.       var oCell = oCaptureRow.insertCell(oCaptureRow.cells.length);
  215.       oCell.innerHTML = "<NOBR>" + this.Columns[i].Capture + "</NOBR>";
  216.     }
  217.     iOffset = 1;
  218.   };
  219.  
  220.   if( this.Style & LCF_SHOWGRID )
  221.   {
  222.     this.table.style.borderRight = "gray 1px solid";
  223.     this.table.style.borderBottom = "gray 1px solid";
  224.   }
  225.   else
  226.   {
  227.     this.table.style.borderRight = "gray 0px solid";
  228.     this.table.style.borderBottom = "gray 0px solid";
  229.   }
  230.  
  231.   for(iCurrentRow = 0; iCurrentRow < this.RowsCount; ++iCurrentRow )
  232.   {
  233.     var oRow    = this.table.rows[iCurrentRow + iOffset];
  234.     
  235.     for( iIndex = 0; iIndex < this.ColumnsCount; ++iIndex )
  236.     {
  237.       var oColumn = this.Columns[iIndex];
  238.       var sCellValue = oColumn.Cells[iCurrentRow].Value;
  239.       if( oColumn.Cells[iCurrentRow].Empty == true )
  240.         continue;
  241.       var oCell = oRow.insertCell( iIndex );
  242.       
  243.       oCell.innerHTML             = sCellValue;
  244.       oCell.width                 = oColumn.Width;
  245.       oCell.style.cellPadding     = 1;
  246.       oCell.style.cellSpacing     = 1;
  247.       
  248.       if( this.Style & LCF_SHOWGRID )
  249.       {
  250.         oCell.style.borderLeft = "gray 1px solid";
  251.         oCell.style.borderTop = "gray 1px solid";
  252.       }
  253.  
  254.       if( oCell.children.length > 0 )
  255.       {
  256.         oCell.style.backgroundColor = oCell.children[0].currentStyle.backgroundColor;
  257.         oCell.style.textAlign       = oCell.children[0].currentStyle.textAlign;
  258.         oCell.style.verticalAlign   = oCell.children[0].currentStyle.verticalAlign;
  259.         oCell.children[0].style.backgroundColor = "";
  260.       }
  261.       oCell.listCtrl              = this;
  262.       oCell.colSpan               = oColumn.Cells[iCurrentRow].ColumnsCount;
  263.       oCell.style.zIndex          = 2;
  264.       
  265.       if( this.GetStyle() & LCF_HIGHLIGHT )
  266.       {
  267.         oCell.onmouseenter = HighlightCell;
  268.         oCell.onmouseleave = UnhighlightCell;
  269.       }
  270.     }
  271.   }
  272. }
  273.  
  274. function HighlightCell()
  275. {
  276.   var oCell = event.srcElement;
  277.   var oRow = oCell.parentElement;
  278.   for( i = 0; i < oRow.cells.length; ++i )
  279.   {
  280.     oCell = oRow.cells[i];
  281.     oCell._oldBgColor = oCell.style.backgroundColor;
  282.     oCell.style.backgroundColor = oCell.listCtrl.HighlightColor;
  283.   };
  284. };
  285.  
  286. function UnhighlightCell()
  287. {
  288.   var oCell = event.srcElement;
  289.   var oRow = oCell.parentElement;
  290.   for( i = 0; i < oRow.cells.length; ++i )
  291.   {
  292.     oCell = oRow.cells[i];
  293.     oCell.style.backgroundColor = oCell._oldBgColor;
  294.   };
  295. }
  296.  
  297. function _ListCtrl_ClearTable()
  298. {
  299.   if( typeof(this.table) == 'undefined' || this.table == null )
  300.     return;
  301.     
  302.   for( ; this.table.rows.length > 0; )
  303.   {
  304.     var oRow = this.table.rows[this.table.rows.length - 1];
  305.     for(; oRow.cells.length > 0; )
  306.       oRow.deleteCell(0);
  307.       
  308.     this.table.deleteRow(0);
  309.   }
  310. };
  311.  
  312.  
  313. function _ListCtrl_SetWidth( p_iColumnIndex, p_sWidth )
  314. {
  315.   if( typeof(this.table) == 'undefined' || this.table == null )
  316.     return;
  317.     
  318.   if( p_iColumnIndex == null || p_sWidth == null )
  319.     return;
  320.     
  321.   var oRow = this.table.rows[0];
  322.   if( oRow == null || oRow.cells[p_iColumnIndex] == null )
  323.     return;
  324.   
  325.   oRow.cells[p_iColumnIndex].width = p_sWidth;
  326. };